package com.lindenvalley.ch.adapters;

import android.content.Context;
import android.graphics.Color;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lindenvalley.ch.AbstractHomeActivity;
import com.lindenvalley.ch.R;
import com.lindenvalley.ch.content.Week;
import com.lindenvalley.ch.content.Weeks;

public class RenameWeekTaskAdapter extends AbstractWeekTaskAdapter{

	public RenameWeekTaskAdapter(Context context, int textViewResourceId, Weeks weeks){
		super(context, textViewResourceId, weeks);
	}
	
	
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		
		if (mWeeks == null)
			return null;		
		
		if (convertView == null){
			convertView = inflater.inflate(mResource, parent, false);
		}
		
		Week week = mWeeks.getWeek(position);
		TextView tv = (TextView) convertView.findViewById(R.id.searchTextView);
		setItemText(tv,week);
		
		return convertView;
	}

	
	protected void setItemText(TextView tv, Week week){		
		String weekOfYear = "";
		mCalendar.setTimeInMillis(week.getStartDate() * 1000L);
		weekOfYear = String.valueOf(AbstractHomeActivity.getWeekOfYear(mCalendar));
		
		String dateText = week.getShortStartDate() + " - " + week.getShortEndDate();			
		String text = KALENDER_TEXT + weekOfYear +": " + dateText;
//		int indexsAusbild = text.length();
//		int index = text.indexOf('\n');
		SpannableString spanString = new SpannableString(text);
//		spanString.setSpan(new ForsegroundColorSpan(mContext.getResources().getColor(R.color.colorDarkOrange)), 0, index, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		spanString.setSpan(new ForegroundColorSpan(Color.BLACK), 0, text.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
		tv.setText(spanString);
			
	}

		
}

